package com.virgo.demo.cms.controller.admin;

import com.virgo.common.entity.IResponse;
import com.virgo.common.entity.ListDataVo;
import com.virgo.demo.cms.domain.bo.HelpCenterBo;
import com.virgo.demo.cms.domain.vo.HelpCenterInfoVo;
import com.virgo.demo.cms.domain.vo.HelpCenterListVo;
import com.virgo.demo.cms.service.HelpCenterService;
import com.virgo.demo.core.annotation.Log;
import com.virgo.limit.annotation.RepeatSubmit;
import com.virgo.web.utils.IRequestUtils;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/manage168/helpCenter")
@RequiredArgsConstructor
public class HelpCenterController {

	private final HelpCenterService helpCenterService;

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	@Log(module = "帮助中心", type = "编辑", permission = "help_center_save")
	@RepeatSubmit
	public IResponse<Void> saveAction(@Validated HelpCenterBo helpCenterBo) {
		helpCenterService.saveHelpCenter(helpCenterBo);
		return IResponse.ok();
	}

	@RequestMapping(value = "/del", method = RequestMethod.POST)
	@Log(module = "帮助中心", type = "删除", permission = "help_center_del")
	@RepeatSubmit
	public IResponse<Void> delAction(HttpServletRequest request) {
		String ids = IRequestUtils.getString(request,"ids","");
		if (ObjectUtils.isEmpty(ids)) {
			return IResponse.fail("参数错误");
		}
		helpCenterService.deleteHelpCenter(ids);
		return IResponse.ok();
	}

	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@Log(permission = "help_center_list", saveLog = false)
	public IResponse<ListDataVo<HelpCenterListVo>> listAction(HttpServletRequest request) {
		return IResponse.ok(helpCenterService.findList(request));
	}

    @RequestMapping(value = "/info", method = RequestMethod.POST)
    @Log(permission = "help_center_save", saveLog = false)
    public IResponse<HelpCenterInfoVo> infoAction(HttpServletRequest request) {
        long id = IRequestUtils.getLong(request,"id");
        if (id < 1L) {
            return IResponse.fail("参数错误");
        }
        return IResponse.ok(helpCenterService.findInfo(id));
    }
}